home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / source / ctlmod / monitor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-16  |  2.0 KB  |  108 lines

  1. # include    <useful.h>
  2. # include    <opsys.h>
  3. # include    <pmon.h>
  4.  
  5. /*
  6. **  MARKPERF -- mark the performance info in a monitor struct
  7. **
  8. **    At any point, there is a monitor struct representing the
  9. **    current object running.  This is stored in the static
  10. **    variable "curmon".  This call essentially does a "context
  11. **    switch" to the structure passed as the argument.
  12. **
  13. **    Parameters:
  14. **        mbuf -- a pointer to a monitor struct.
  15. **
  16. **    Returns:
  17. **        a pointer to the previous monitor struct.
  18. **
  19. **    Side Effects:
  20. **        none
  21. */
  22.  
  23. struct tbuffer
  24. {
  25.     long    tms_utime;
  26.     long    tms_stime;
  27.     long    tms_cutime;
  28.     long    tms_cstime;
  29. };
  30.  
  31. struct monitor *
  32. markperf(mbuf)
  33. register struct monitor    *mbuf;
  34. {
  35.     struct tbuffer        tbuf;
  36.     register long        ut;
  37.     register long        st;
  38.     static struct tbuffer    baset;
  39.     static struct monitor    *curmon;
  40.     register struct monitor    *oldmon;
  41.  
  42.     times(&tbuf);
  43.  
  44.     ut = tbuf.tms_utime + tbuf.tms_cutime - baset.tms_utime - baset.tms_cutime;
  45.     st = tbuf.tms_stime + tbuf.tms_cstime - baset.tms_stime - baset.tms_cstime;
  46.     oldmon = curmon;
  47.     if (oldmon != NULL)
  48.     {
  49.         oldmon->mon_utime += ut;
  50.         oldmon->mon_stime += st;
  51.     }
  52.     curmon = mbuf;
  53.     bmove(&tbuf, &baset, sizeof baset);
  54.     return (oldmon);
  55. }
  56. /*
  57. **  ADD_MON -- "add" two monitor structs
  58. **
  59. **    The logical sum of two monitor structs is created
  60. **
  61. **    Parameters:
  62. **        a -- the first monitor struct
  63. **        b -- the second monitor struct; gets the result.
  64. **
  65. **    Returns:
  66. **        none (value is returned through b)
  67. **
  68. **    Side Effects:
  69. **        none.
  70. */
  71.  
  72. add_mon(a, b)
  73. register struct monitor    *a;
  74. register struct monitor    *b;
  75. {
  76.     b->mon_utime += a->mon_utime;
  77.     b->mon_stime += a->mon_stime;
  78. }
  79. /*
  80. **  CVT_TIME -- convert time for output
  81. **
  82. **    Converts a time in ticks to a string (in seconds) for
  83. **    printing.
  84. **
  85. **    Parameters:
  86. **        t -- time in ticks
  87. **
  88. **    Returns:
  89. **        pointer to string suitable for printing or framing.
  90. **
  91. **    Side Effects:
  92. **        previous return value is clobbered.
  93. */
  94.  
  95. #ifndef HZ
  96. #define HZ 60
  97. #endif
  98.  
  99. char *
  100. cvt_time(t)
  101. long    t;
  102. {
  103.     static char    buf[30];
  104.  
  105.     sprintf(buf, "%.3f", ((float) t) / ((float) HZ));
  106.     return (buf);
  107. }
  108.